package org.moflon.moca;

import java.io.File;

import modeltotree.ModeltotreeFactory;
import modeltotree.ModeltotreePackage;
import modeltotree.TransformModelToTree;

import org.apache.log4j.BasicConfigurator;
import org.moflon.moca.html.unparser.HtmlUnparserAdapter;
import org.moflon.moca.txt.unparser.TxtUnparserAdapter;
import org.moflon.util.eMoflonEMFUtil;

import BoardGame.Board;
import BoardGame.BoardGamePackage;
import Moca.CodeAdapter;
import Moca.MocaFactory;
import MocaTree.Folder;
import MocaTree.MocaTreePackage;
import Rules.RulesPackage;

public class MocaMain 
{

  private static CodeAdapter codeAdapter;

  public static void main(String[] args) 
  {
    BasicConfigurator.configure();
    MocaTreePackage.eINSTANCE.getName();
    BoardGamePackage.eINSTANCE.getName();
	RulesPackage.eINSTANCE.getName();

    // Register parsers and unparsers
    codeAdapter = MocaFactory.eINSTANCE.createCodeAdapter();
    //codeAdapter.getUnparser().add(new TxtUnparserAdapter());
    codeAdapter.getUnparser().add(new HtmlUnparserAdapter());
    
    // load the model
    Board board = (Board) eMoflonEMFUtil.loadModel(BoardGamePackage.eINSTANCE, "instances/in/board.xmi", null);
    
    TransformModelToTree transformer = ModeltotreeFactory.eINSTANCE.createTransformModelToTree();
    MocaTree.File tree = transformer.transform(board);

    // save the tree
    eMoflonEMFUtil.saveModel(ModeltotreePackage.eINSTANCE, tree, "instances/tree.xmi");
    
    File out = new File("instances/out");

    // Perform tree-to-text
    codeAdapter.unparseFile(tree, out);
    }
}